<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style type="text/css">

        td{
            width: 16%;
        }
    </style>
    <link href="/resources/css/table.css?r=3" rel="stylesheet">
    <script src="/resources/js/jquery-1.11.1.min.js"></script>
    <script src="/resources/js/self.js"></script>
    <script type="text/javascript" src="/resources/js/md5.js"></script>
    <script type="text/javascript" src="/resources/My97DatePicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/resources/js/ajaxfileupload.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <script src="/resources/js/fk.js"></script>
    <link href="/resources/video/css/video-js.css" rel="stylesheet">
    <script src="/resources/video/js/video.min.js"></script>
    <script src="/resources/video/js/videojs-contrib-hls.js"></script>
</head>
<body>
<div   class="row form-inline" style="margin-left: 20px;margin-top: 10px;">
    <button type="button" onclick="showRegister()" class="btn btn-success">企业备案</button>
    <button type="button" onclick="showPractitioner()" class="btn btn-success">从业人员</button>
    <button type="button" onclick="showSecurityPeople()" class="btn btn-success">保卫机构</button>
    <button type="button" onclick="showPurchasePeople()" class="btn btn-success">采购部</button>
    <button type="button" onclick="showSeller()" class="btn btn-success">销售部</button>
    <button type="button" onclick="modifyCDevice()" class="btn btn-success">维护设备</button>
    <button type="button" onclick="modifyCUser()" class="btn btn-success">维护账号</button>
    <button type="button" onclick="back()" class="btn btn-success">返回</button>
</div>
<table  style="width:100%;margin-top: 10px;">

    <tr>
        <td class="name"  style="height:50px">企业名称:</td>
        <td name="name" class="form-data value" ></td>
        <td  class="name" style="height:50px">行业:</td>
        <td name="business" class="form-data value" ></td>
        <td class="name">法人照片</td>
        <td class="name">实景照片</td>

    </tr>
    <tr>

    </tr>
    <tr>
        <td  class="name" style="height:50px">建立时间:</td>
        <td name="startTime" class="form-data value" ></td>
        <td  class="name" style="height:50px">法人:</td>
        <td name="personInCharge" class="form-data value" ></td>
        <td rowspan="3" class="value">
            <div id="imgDiv2" >
                <img src="" style="cursor: pointer; width:180px;height: 180px"  />
            </div>
        </td>
        <td rowspan="3" class="value">
            <div id="imgDiv" >
                <img src="" style="cursor: pointer; width:180px;height: 180px"  />
            </div>
        </td>

    </tr>
    <tr>

        <td  class="name" style="height:50px">身份证号:</td>
        <td name="idCard" class="form-data value" ></td>
        <td  class="name" style="height:50px">性别:</td>
        <td name="sex" class="form-data value" ></td>
    </tr>
    <tr>

        <td  class="name" style="height:50px">电话:</td>
        <td name="telephone" class="form-data value" ></td>
        <td  class="name" style="height:50px">住址:</td>
        <td name="personAddress" class="form-data value" ></td>
    </tr>
    <tr>
        <td  class="name" colspan="4" style="text-align: left;"></td>

        <td  class="name" >视频</td>
        <td  class="name" ><button id="playVideo" onclick="openVideo()">打开视频</button></td>

    </tr>
    <tr>
        <td  class="name" colspan="6" style="text-align: left;">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp企业简介:</td>



    </tr>
    <tr>
        <td name="desc" class="form-data value" colspan="6" height="300px;"  valign="top"
            style="height:350px;white-space:normal !important;text-align: left" >

        </td>

    </tr>


</table>

</body>
<script type="text/javascript">
    $(function () {
        setTitle("基本信息>企业信息");
        initData();

    });
    function playVideo() {
        var player = videojs('example-video');
        player.play();
    }
    function initData(){
        var data = getData();
        var id = data.id;
        if(null2empty(id) !==""){
            $("input[name='id']").val(id);
            $.ajax({
                url:"/admin/company/find.do",
                data:{'id':id},
                type:'post',
                async:false,
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if(data.success){
                        initPageDate(data.data, '.form-data');
                        $("#imgDiv img").attr("src",data.data.image);
                        $("#imgDiv2 img").attr("src", data.data.legalPersonPhotos);

                       $("#playVideo").attr("data",data.data.videoCode);
                        addFileInfoToTable(data.data.fileInfoList,'file');
                    }
                }
            });
            $("#account").attr('readonly','readonly');
        }

    }

    function save() {
        var params = getPageDataByClass("form-data");
        if (strIsNull(params['name'])) {
            alert("请输入企业名称");
            return;
        }
        if (strIsNull(params['business'])) {
            alert("请输入企业所属行业");
            return;
        }
        if (strIsNull(params['status'])) {
            alert("请选择企业状态");
            return;
        }
        var img = $("#imgDiv img");
        if(img.length > 0) {
            params['image'] = $(img[0]).attr("src");
        }else{
            alert("请上传实景照片");
            return;
        }
        params.regulation = "";
        $("input[name='file_id']").each(function(index,files){
            if(files == "") {
                params.regulation = $(this).val();
            } else {
                params.regulation = params.regulation + "," + $(this).val();
            }
        });
        params['legalPersonPhotos'] = getImagePath("legalPersonPhotos");
        $.ajax({
            url: "/admin/company/save.do",
            data: params,
            dataType: 'json',
            type: 'post',
            success: function (data) {
                console.log(data);
                if (data.success) {
                    alert("保存成功");
                    goto("company_list.html");
                } else {
                    alert(data.msg);
                }
            }
        });
    }
    function back() {
        goto("company_list.html");
    }
    function downLoadFile() {
        var url = $("input[name='regulation']").val();
        window.open(url,"_blank");
    }
    function uploadFileId(fileType) {
        $.ajaxFileUpload({
            url: "/file/uploadFile.do?_t=" + new Date().getTime(),            //需要链接到服务器地址
            secureuri: false,//是否启用安全提交，默认为false
            fileElementId: fileType+'_input',                        //文件选择框的id属性
            dataType: 'text',                                     //服务器返回的格式，可以是json, xml
            success: function (data, status) {//服务器成功响应处理函数
                var rpeObj = $.parseJSON(data);
                var fileInfoList = rpeObj.data;
                addFileInfoToTable(fileInfoList,fileType);

            }
        });
    }
    function addFileInfoToTable(fileInfoList,fileType){
        $(fileInfoList).each(function(index,file){

            var fileHtml = "<div  onclick='downLoadFileId(\""+file.path+"\",\""+file.name+"\")' " +
                "style='border-radius: 2px; width:30%;height:100px;float: left; border: 2px #ffffff solid;'>"+

                "<div align='center' style='height:80px;margin-bottom: 0px;'>"+
                "<div align='center' onclick='downLoadFile(\""+file.path+"\",\""+file.name+"\")' >"+file.name+"</div>"+
            "</div>";
            $("#"+fileType+"_div").html(fileHtml);

        });
        $("button[name='delete']").unbind('click');
        $("button[name='delete']").click(function(){
            var id = $(this).attr("extendData");
            $.ajax({
                type: "POST",
                url: "/file/delete.do?_t=" + new Date().getTime(),
                data: "fileId=" + id,

                success: function (result) {
                    alert("删除成功");
                },

                error: function (XMLHttpRequest, textStatus, thrownError) {
                    /* alert("系统异常");*/
                }
            });
            $(this).parent().parent().remove();
        });
    }
    function modifyCUser(){
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        goto("company_user_edit.html",{"companyId":companyId});
    }
    function showPractitioner() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){

            return;
        }
        goto("practitioner_list.html",{"companyId":companyId});
    }
    function showSecurityPeople() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){

            return;
        }
        goto("practitioner_list.html",{"companyId":companyId,"securityPeople":"valid"});
    }
    function showPurchasePeople() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){

            return;
        }
        goto("practitioner_list.html",{"companyId":companyId,"purchasePeople":"valid"});
    }
    function showSeller() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){

            return;
        }
        goto("practitioner_list.html",{"companyId":companyId,"seller":"valid"});
    }
    function modifyCDevice() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        goto("device_list.html",{"companyId":companyId});
    }
    function showRegister() {
        var companyId = getOneSelectChecked();
        if(isNullOrUndefined(companyId)){
            alert("请选择要修改的数据,并且只能选择一条");
            return;
        }
        goto("companyRegister_show.html",{"companyId":companyId,"data_type":'company'});
    }
    function getOneSelectChecked() {
        var data = getData();
        var id = data.id;
        return id;
    }
    function back() {
        goto("company_list.html");
    }
    function calcVideoUrl(videoCode) {
        var url = "http://218.57.221.222:6713/mag/hls/"+videoCode+"/1/live.m3u8";
        return url;
    }
    function buildHtml(videoCode) {
        var url = calcVideoUrl(videoCode);
        var videoHtml =
            "<video id='example-video' class='video-js' autoplay='autoplay' controls preload='auto' width='400' height='350' >"+
            "<source id='video-player' src='"+url+"' type='application/x-mpegURL'>"+
            "</video>";
        return videoHtml;
    }
    
    function openVideo() {
        var videoCode = $("#playVideo").attr("data");
        var url = document.location.origin+"/html/security/video_play.html?videoCode="+videoCode;
        tkClick(url);
    }

</script>
</html>